<?php

include('includes/before_html.php');
$db = mysql_connect(db_server, $db_user, $db_password);
mysql_select_db($db_dbname);

echo '<div style="background-color:#ffffff; padding:20px">';
$submit = 0;
$excluded = array('Person1', 'id', 'RUID');
$table = $_GET['t'];
$result = mysql_query("describe $table");
$colnames = '';
$values = '';
$update = '';
while ($row = mysql_fetch_array($result)) {
    if (!in_array($row['Field'], $excluded)) {
        $colnames.=$row['Field'] . ",";
        $val = $_POST[$table . "_" . $row['Field']];
        if (!empty($val) || $val != '') {
            $submit = 1;
            $values.= "'" . $val . "',";
        }
        else{
            $values.="NULL,";
        }
        $update.=$row['Field'] . "='" . $val . "',";
    }
}
if($table=='Relationships'){
    $colnames.="Person1";
}
else{
    $colnames.="RUID";
}

$values.=$myRuid;

$update = substr($update, 0, strlen($update) - 1);

if ($submit) {
    $sql = "INSERT INTO $table ($colnames) VALUES ($values)";
    echo "SQL QUERY: " . $sql . "<BR><BR>";
    if ($result = mysql_query($sql))
        echo "Values ($values) have been added to $table.";
    else
        echo "ERROR: ".mysql_error();

    outputQueryResults("SELECT * FROM $table WHERE RUID=$myRuid");
}
else {
    echo "Nothing has been entered.";
}
echo '</div>';
?>
